import request from '@/sheep/request';

interface Order {
  // 定义订单数据类型
  // 根据实际情况添加属性
}

interface SettlementData {
  // 定义结算订单数据类型
  // 根据实际情况添加属性
}

interface OrderItem {
  // 定义订单项数据类型
  // 根据实际情况添加属性
}

interface ExpressTrack {
  // 定义物流轨迹数据类型
  // 根据实际情况添加属性
}

const OrderApi = {
  settlementOrder: (data: SettlementData): Promise<Order> => {
    // 对 data 进行处理，移除多余字段等
    // ...

    return request({
      url: `/trade/order/settlement`,
      method: 'GET',
      params: data,
      custom: {
        showError: true,
        showLoading: true,
      },
    });
  },
  createOrder: (data: Order): Promise<void> => {
    return request({
      url: `/trade/order/create`,
      method: 'POST',
      data,
    });
  },
  getOrder: (id: number): Promise<Order> => {
    return request({
      url: `/trade/order/get-detail`,
      method: 'GET',
      params: {
        id,
      },
      custom: {
        showLoading: false,
      },
    });
  },
  getOrderPage: (params: any): Promise<Order[]> => {
    return request({
      url: '/trade/order/page',
      method: 'GET',
      params,
      custom: {
        showLoading: false,
      },
    });
  },
  receiveOrder: (id: number): Promise<void> => {
    return request({
      url: `/trade/order/receive`,
      method: 'PUT',
      params: {
        id,
      },
    });
  },
  cancelOrder: (id: number): Promise<void> => {
    return request({
      url: `/trade/order/cancel`,
      method: 'DELETE',
      params: {
        id,
      },
    });
  },
  deleteOrder: (id: number): Promise<void> => {
    return request({
      url: `/trade/order/delete`,
      method: 'DELETE',
      params: {
        id,
      },
    });
  },
  getOrderExpressTrackList: (id: number): Promise<ExpressTrack[]> => {
    return request({
      url: `/trade/order/get-express-track-list`,
      method: 'GET',
      params: {
        id,
      },
    });
  },
  getOrderCount: (): Promise<number> => {
    return request({
      url: '/trade/order/get-count',
      method: 'GET',
      custom: {
        showLoading: false,
        auth: true,
      },
    });
  },
  createOrderItemComment: (data: OrderItem): Promise<void> => {
    return request({
      url: `/trade/order/item/create-comment`,
      method: 'POST',
      data,
    });
  },
};

export default OrderApi;
